//
//  YWSingleMonthModel.m
//  YWCalendar
//
//  Created by YR on 2017/5/25.
//  Copyright © 2017年 YR. All rights reserved.
//

#import "YWSingleMonthModel.h"

#import "NSCalendar+YWDateConvertor.h"

@implementation YWSingleMonthModel

- (instancetype)initWithYear:(NSInteger)year month:(NSInteger)month  {
    self = [super init];
    if (self) {
        _currentYear = year;
        _currentMonth = month;
        NSCalendar *calendar = [NSCalendar currentCalendar];
        NSDate *currentMonthFirstDayDate = [calendar yw_dateFromYear:year
                                                                month:month
                                                                  day:1];
        NSInteger currentMonthFirstDayWeekDay = [calendar component:NSCalendarUnitWeekday fromDate:currentMonthFirstDayDate];
        //  上个月可以显示几天
        NSInteger dayOffsetCount = currentMonthFirstDayWeekDay - 1;
        _calendarStartDayDate = [calendar yw_dateFromDate:currentMonthFirstDayDate
                                             withDayOffset:-dayOffsetCount];
        _calendarEndDayDate = [calendar yw_dateFromDate:self.calendarStartDayDate
                                           withDayOffset:7 * kRows];
    }
    return self;
}


@end
